package org.example.analysis.service.analyzer;

import lombok.extern.slf4j.Slf4j;
import org.example.analysis.model.entity.EntryPointInfo;
import org.example.analysis.model.MethodComplexity;
import org.example.analysis.service.MethodComplexityAnalyzer;
import org.example.analysis.service.dataobj.ClassDataObject;
import org.example.analysis.service.dataobj.MethodDataObject;
import org.example.analysis.service.dataobj.ProjectDataObject;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * 入口方法分析器 - 分析项目的入口方法
 */
@Slf4j
public class EntryPointAnalyzer {
    private static final Pattern URL_PATTERN = Pattern.compile("@[A-Za-z]+Mapping\\s*\\(\\s*[\"']([^\"']+)[\"']\\s*\\)");
    
    private final MethodComplexityAnalyzer complexityAnalyzer;
    
    public EntryPointAnalyzer() {
        this.complexityAnalyzer = new MethodComplexityAnalyzer();
    }
    
    /**
     * 分析项目的入口方法
     *
     * @param classInfoList 类信息列表
     * @return 入口方法列表
     */
    public List<EntryPointInfo> analyze(ProjectDataObject projectDataObject) {
        List<EntryPointInfo> entryPoints = new ArrayList<>();
        
        for (ClassDataObject classInfo : projectDataObject.getClassDataObjects()) {
            try {
                log.info("分析类: {}", classInfo.getClassName());
                // 分析类中的入口方法
                analyzeClassEntryPoints(projectDataObject.getClassDataObjects(),classInfo, entryPoints);
            } catch (Exception e) {
                log.error("分析入口点失败: {}", classInfo.getClassName(), e);
            }
        }
        
        return entryPoints;
    }
    
    /**
     * 分析类中的入口方法
     */
    private void analyzeClassEntryPoints(List<ClassDataObject> allClasses,ClassDataObject classInfo, List<EntryPointInfo> entryPoints) {
        // 检查类级别的注解
        boolean isController = isController(classInfo);

        // 遍历类中的所有方法
        for (MethodDataObject methodInfo : classInfo.getMethods()) {
            EntryPointInfo entryPoint = null;
            
            // 1. 检查是否是Controller入口
            if (isController && isRequestMapping(methodInfo)) {
                entryPoint = createEntryPoint(classInfo, methodInfo, EntryPointInfo.EntryType.API.name());
                String url = extractUrl(methodInfo);
                if (url != null) {
                    entryPoint.setEntryPath(url);
                }
                // 设置HTTP方法
                String httpMethod = getHttpMethod(methodInfo);
                if (httpMethod != null) {
                    entryPoint.setHttpMethod(httpMethod);
                }
            }
            // 2. 检查是否是测试入口
            else if (isTestMethod(methodInfo)) {
                entryPoint = createEntryPoint(classInfo, methodInfo, "TEST");
            }
            // 3. 检查是否是Main方法
            else if (isMainMethod(methodInfo)) {
                entryPoint = createEntryPoint(classInfo, methodInfo, EntryPointInfo.EntryType.MAIN.name());
            }
            // 4. 检查是否是定时任务入口
            else if (hasScheduledAnnotation(methodInfo)) {
                entryPoint = createEntryPoint(classInfo, methodInfo, EntryPointInfo.EntryType.SCHEDULER.name());
            }
            // 5. 检查是否是消息队列监听入口
            else if (hasMQListenerAnnotation(methodInfo)) {
                entryPoint = createEntryPoint(classInfo, methodInfo, EntryPointInfo.EntryType.MQ.name());
            }
            // 6. 检查是否是多线程入口
            else if (isThreadEntry(classInfo, methodInfo)) {
                entryPoint = createEntryPoint(classInfo, methodInfo, EntryPointInfo.EntryType.THREAD.name());
                String businessLogic = getThreadBusinessLogic(classInfo, methodInfo);
                entryPoint.setBusinessLogic(businessLogic);
            }
            // 7. 检查是否是Redis队列处理入口
            else if (isRedisQueueEntry(methodInfo)) {
                entryPoint = createEntryPoint(classInfo, methodInfo, EntryPointInfo.EntryType.REDIS_QUEUE.name());
                String queueKey = extractQueueKeyFromAnnotation(methodInfo.getAnnotations().toString());
                if (!queueKey.isEmpty()) {
                    entryPoint.setEntryPath(queueKey);
                }
                entryPoint.setBusinessLogic("Redis队列处理方法");
            }
            
            // 如果是入口点，计算复杂度并添加到列表
            if (entryPoint != null) {
                // 计算方法复杂度
                MethodComplexity complexity = complexityAnalyzer.analyze(allClasses,methodInfo,classInfo);
                entryPoint.setComplexity(complexityAnalyzer.calculateComplexityScore(complexity));
                // 设置方法注释
                entryPoint.setMethodComment(methodInfo.getMethodComment());
                entryPoints.add(entryPoint);
                log.debug("发现入口点: {}.{}, 类型: {}", classInfo.getClassName(), methodInfo.getMethodName(), entryPoint.getEntryType());
            }
        }
    }
    
    /**
     * 创建入口点信息
     */
    private EntryPointInfo createEntryPoint(ClassDataObject classInfo, MethodDataObject methodInfo, String entryType) {
        EntryPointInfo entryPoint = new EntryPointInfo();
        entryPoint.setProjectName(classInfo.getProjectName());
        entryPoint.setClassName(classInfo.getClassName());
        entryPoint.setPackageName(classInfo.getPackageName());
        entryPoint.setMethodName(methodInfo.getMethodName());
        entryPoint.setEntryType(entryType);
       // entryPoint.setComment(methodInfo.getComment());
        return entryPoint;
    }
    
    /**
     * 检查是否是Controller类
     */
    private boolean isController(ClassDataObject classInfo) {
        return classInfo.getAnnotations().stream()
                .anyMatch(annotation -> annotation.contains("Controller") || 
                         annotation.contains("RestController"));
    }
    
    /**
     * 检查是否是测试类
     */
    private boolean isTest(ClassDataObject classInfo) {
        return classInfo.getAnnotations().stream()
                .anyMatch(annotation -> annotation.contains("Test"));
    }
    
    /**
     * 检查是否是请求映射方法
     */
    private boolean isRequestMapping(MethodDataObject methodInfo) {
        return methodInfo.getModifiers().stream()
                .anyMatch(mod -> mod.contains("@RequestMapping") ||
                        mod.contains("@GetMapping") ||
                        mod.contains("@PostMapping") ||
                        mod.contains("@PutMapping") ||
                        mod.contains("@DeleteMapping") ||
                        mod.contains("@PatchMapping"));
    }
    
    /**
     * 检查是否是测试方法
     */
    private boolean isTestMethod(MethodDataObject methodInfo) {
        return methodInfo.getAnnotations().stream()
                .anyMatch(annotation -> annotation.contains("Test"));
    }
    
    /**
     * 检查是否是Main方法
     */
    private boolean isMainMethod(MethodDataObject methodInfo) {
        return "main".equals(methodInfo.getMethodName()) &&
               methodInfo.getModifiers().contains("public") &&
               methodInfo.getModifiers().contains("static");
    }
    
    /**
     * 提取URL路径
     */
    private String extractUrl(MethodDataObject methodInfo) {
        for (String annotation : methodInfo.getAnnotations()) {
            var matcher = URL_PATTERN.matcher(annotation);
            if (matcher.find()) {
                return matcher.group(1);
            }
        }
        return null;
    }
    
    /**
     * 分析主方法入口
     */
    private void analyzeMainMethod(ClassDataObject classInfo, MethodDataObject methodInfo, List<EntryPointInfo> entryPoints) {
        if ("main".equals(methodInfo.getMethodName()) &&
            methodInfo.getModifiers().contains("public") &&
            methodInfo.getModifiers().contains("static") &&
            "void".equals(methodInfo.getReturnType()) &&
            hasStringArrayParameter(methodInfo)) {
            EntryPointInfo entryPoint = new EntryPointInfo();
            entryPoint.setEntryType("MAIN");
            entryPoint.setClassName(classInfo.getClassName());
            entryPoint.setMethodName(methodInfo.getMethodName());
            entryPoint.setMethodComment(methodInfo.getMethodComment());
            entryPoints.add(entryPoint);
        }
    }
    
    /**
     * 分析API接口入口
     */
    private void analyzeApiMethod(ClassDataObject classInfo, MethodDataObject methodInfo, List<EntryPointInfo> entryPoints) {
        String baseUrl = getBaseUrl(classInfo);
        
        String httpMethod = getHttpMethod(methodInfo);
        if (httpMethod != null) {
            String methodUrl = getMethodUrl(methodInfo);
            
            EntryPointInfo entryPoint = new EntryPointInfo();
            entryPoint.setEntryType("API");
            entryPoint.setClassName(classInfo.getClassName());
            entryPoint.setMethodName(methodInfo.getMethodName());
            entryPoint.setEntryPath(combineUrl(baseUrl, methodUrl));
            entryPoint.setHttpMethod(httpMethod);
            entryPoint.setMethodComment(methodInfo.getMethodComment());
            entryPoints.add(entryPoint);
        }
    }
    
    /**
     * 分析定时任务入口
     */
    private void analyzeSchedulerMethod(ClassDataObject classInfo, MethodDataObject methodInfo, List<EntryPointInfo> entryPoints) {
        if (hasScheduledAnnotation(methodInfo)) {
            EntryPointInfo entryPoint = new EntryPointInfo();
            entryPoint.setEntryType("SCHEDULER");
            entryPoint.setClassName(classInfo.getClassName());
            entryPoint.setMethodName(methodInfo.getMethodName());
            entryPoint.setMethodComment(methodInfo.getMethodComment());
            entryPoints.add(entryPoint);
        }
    }
    
    /**
     * 分析消息监听入口
     */
    private void analyzeMQMethod(ClassDataObject classInfo, MethodDataObject methodInfo, List<EntryPointInfo> entryPoints) {
        if (hasMQListenerAnnotation(methodInfo)) {
            EntryPointInfo entryPoint = new EntryPointInfo();
            entryPoint.setEntryType("MQ");
            entryPoint.setClassName(classInfo.getClassName());
            entryPoint.setMethodName(methodInfo.getMethodName());
            entryPoint.setMethodComment(methodInfo.getMethodComment());
            entryPoints.add(entryPoint);
        }
    }
    
    /**
     * 分析多线程入口方法
     */
    private void analyzeThreadMethod(ClassDataObject classInfo, MethodDataObject methodInfo, List<EntryPointInfo> entryPoints) {
        // 检查方法的修饰符和注解
        List<String> modifiers = methodInfo.getModifiers();
        if (modifiers == null || modifiers.isEmpty()) {
            return;
        }
        
        boolean isThreadEntry = false;
        String businessLogic = "";
        
        // 检查是否实现了Runnable接口
        if (classInfo.getInterfaces().contains("java.lang.Runnable") && 
            methodInfo.getMethodName().equals("run")) {
            isThreadEntry = true;
            businessLogic = "实现Runnable接口的run方法";
        }
        
        // 检查是否实现了Callable接口
        if (classInfo.getInterfaces().contains("java.util.concurrent.Callable") && 
            methodInfo.getMethodName().equals("call")) {
            isThreadEntry = true;
            businessLogic = "实现Callable接口的call方法";
        }
        
        // 检查@Async注解
        for (String modifier : modifiers) {
            if (modifier.startsWith("@Async")) {
                isThreadEntry = true;
                businessLogic = "使用@Async注解的异步方法";
                break;
            }
        }
        
        // 检查方法名和返回类型特征
        if (methodInfo.getMethodName().toLowerCase().contains("async") || 
            methodInfo.getMethodName().toLowerCase().contains("thread")) {
            String returnType = methodInfo.getReturnType();
            if (returnType != null && (
                returnType.contains("Future") || 
                returnType.contains("CompletableFuture") ||
                returnType.contains("Thread"))) {
                isThreadEntry = true;
                businessLogic = "返回Future或Thread的异步方法";
            }
        }
        
        // 如果是线程入口，创建入口点信息
        if (isThreadEntry) {
            EntryPointInfo entryPoint = new EntryPointInfo()
                .setEntryType(EntryPointInfo.EntryType.THREAD.name())
                .setClassName(classInfo.getClassName())
                .setMethodName(methodInfo.getMethodName())
                .setMethodComment(methodInfo.getMethodComment())
                .setBusinessLogic(businessLogic);
            
            entryPoints.add(entryPoint);
            log.debug("发现线程入口: {}.{}", classInfo.getClassName(), methodInfo.getMethodName());
        }
    }
    
    /**
     * 分析Redis队列处理入口方法
     */
    private void analyzeRedisQueueMethod(ClassDataObject classInfo, MethodDataObject methodInfo, List<EntryPointInfo> entryPoints) {
        // 检查方法的修饰符和注解
        List<String> modifiers = methodInfo.getModifiers();
        if (modifiers == null || modifiers.isEmpty()) {
            return;
        }
        
        boolean isRedisQueueEntry = false;
        String businessLogic = "";
        String queueKey = "";
        
        // 检查方法名特征
        String methodName = methodInfo.getMethodName().toLowerCase();
        if (methodName.contains("pop") || methodName.contains("poll") || methodName.contains("consume")) {
            // 检查是否包含Redis相关的参数或返回类型
            boolean hasRedisType = false;
            
            // 检查返回类型
            String returnType = methodInfo.getReturnType();
            if (returnType != null && (returnType.contains("RedisTemplate") || 
                                     returnType.contains("StringRedisTemplate") ||
                                     returnType.contains("RedisConnection"))) {
                hasRedisType = true;
            }
            
            // 检查参数类型
            boolean hasRedisParameter = methodInfo.getParameters().stream()
                    .anyMatch(param -> param.getParameterType().contains("RedisTemplate") ||
                                     param.getParameterType().contains("StringRedisTemplate") ||
                                     param.getParameterType().contains("RedisConnection"));
            
            if (hasRedisType || hasRedisParameter) {
                isRedisQueueEntry = true;
                businessLogic = "Redis队列消费方法";
            }
        }
        
        // 检查Redis相关注解
        for (String modifier : modifiers) {
            // 检查自定义的Redis队列注解
            if (modifier.contains("@RedisQueue") || 
                modifier.contains("@RedisListener") || 
                modifier.contains("@RedisConsumer")) {
                isRedisQueueEntry = true;
                businessLogic = "Redis队列监听方法";
                // 尝试从注解中提取队列key
                queueKey = extractQueueKeyFromAnnotation(modifier);
                break;
            }
        }
        
        // 检查方法注释中的Redis队列关键字
        String methodComment = methodInfo.getMethodComment();
        if (methodComment != null && 
            (methodComment.toLowerCase().contains("redis queue") || 
             methodComment.toLowerCase().contains("redis消息队列") ||
             methodComment.toLowerCase().contains("redis list"))) {
            isRedisQueueEntry = true;
            if (businessLogic.isEmpty()) {
                businessLogic = "Redis队列处理方法";
            }
        }
        
        // 如果是Redis队列入口，创建入口点信息
        if (isRedisQueueEntry) {
            EntryPointInfo entryPoint = new EntryPointInfo()
                .setEntryType(EntryPointInfo.EntryType.REDIS_QUEUE.name())
                .setClassName(classInfo.getClassName())
                .setMethodName(methodInfo.getMethodName())
                .setMethodComment(methodInfo.getMethodComment())
                .setBusinessLogic(businessLogic);
            
            // 如果有队列key，设置为入口路径
            if (!queueKey.isEmpty()) {
                entryPoint.setEntryPath(queueKey);
            }
            
            entryPoints.add(entryPoint);
            log.debug("发现Redis队列入口: {}.{}", classInfo.getClassName(), methodInfo.getMethodName());
        }
    }
    
    /**
     * 获取Controller类的基础URL
     */
    private String getBaseUrl(ClassDataObject classInfo) {
        // 从类的注解中获取基础URL（@RequestMapping的value属性）
        List<String> annotations = classInfo.getModifiers().stream()
                .filter(mod -> mod.contains("@"))
                .collect(Collectors.toList());
        
        for (String annotation : annotations) {
            if (annotation.contains("RequestMapping")) {
                // 尝试从注解中提取URL
                String url = extractUrlFromAnnotation(annotation);
                if (url != null) {
                    return url;
                }
            }
        }
        
        return "";
    }
    
    /**
     * 获取方法的HTTP请求类型
     */
    private String getHttpMethod(MethodDataObject methodInfo) {
        List<String> annotations = methodInfo.getModifiers().stream()
                .filter(mod -> mod.contains("@"))
                .collect(Collectors.toList());
        
        for (String annotation : annotations) {
            if (annotation.contains("GetMapping")) return "GET";
            if (annotation.contains("PostMapping")) return "POST";
            if (annotation.contains("PutMapping")) return "PUT";
            if (annotation.contains("DeleteMapping")) return "DELETE";
            if (annotation.contains("RequestMapping")) return "ANY";
        }
        
        return null;
    }
    
    /**
     * 获取方法的URL
     */
    private String getMethodUrl(MethodDataObject methodInfo) {
        List<String> annotations = methodInfo.getModifiers().stream()
                .filter(mod -> mod.contains("@"))
                .collect(Collectors.toList());
        
        for (String annotation : annotations) {
            if (isUrlMappingAnnotation(annotation)) {
                // 尝试从注解中提取URL
                String url = extractUrlFromAnnotation(annotation);
                if (url != null) {
                    return url;
                }
            }
        }
        
        return "";
    }
    
    /**
     * 合并基础URL和方法URL
     */
    private String combineUrl(String baseUrl, String methodUrl) {
        if (baseUrl == null || baseUrl.isEmpty()) return methodUrl;
        if (methodUrl == null || methodUrl.isEmpty()) return baseUrl;
        
        baseUrl = baseUrl.endsWith("/") ? baseUrl.substring(0, baseUrl.length() - 1) : baseUrl;
        methodUrl = methodUrl.startsWith("/") ? methodUrl : "/" + methodUrl;
        
        return baseUrl + methodUrl;
    }
    
    /**
     * 检查方法是否有定时任务注解
     */
    private boolean hasScheduledAnnotation(MethodDataObject methodInfo) {
        return methodInfo.getModifiers().stream()
                .anyMatch(mod -> mod.contains("@Scheduled"));
    }
    
    /**
     * 检查方法是否有消息监听注解
     */
    private boolean hasMQListenerAnnotation(MethodDataObject methodInfo) {
        return methodInfo.getModifiers().stream()
                .anyMatch(mod -> mod.contains("@RabbitListener") || 
                        mod.contains("@KafkaListener") ||
                        mod.contains("@JmsListener"));
    }
    
    /**
     * 检查是否是URL映射注解
     */
    private boolean isUrlMappingAnnotation(String annotation) {
        return annotation.contains("RequestMapping") ||
                annotation.contains("GetMapping") ||
                annotation.contains("PostMapping") ||
                annotation.contains("PutMapping") ||
                annotation.contains("DeleteMapping") ||
                annotation.contains("PatchMapping");
    }
    
    /**
     * 从注解中提取URL!
     * 支持以下格式：
     * @RequestMapping("/path")
     * @RequestMapping(value = "/path")
     * @RequestMapping(path = "/path")
     * @GetMapping("/path")
     * 等
     */
    private String extractUrlFromAnnotation(String annotation) {
        try {
            // 匹配简单格式：@XXXMapping("/path")
            Pattern simplePattern = Pattern.compile("@\\w+Mapping\\(\\s*\"([^\"]+)\"\\s*\\)");
            Matcher simpleMatcher = simplePattern.matcher(annotation);
            if (simpleMatcher.find()) {
                return simpleMatcher.group(1);
            }
            
            // 匹配带属性格式：@XXXMapping(value = "/path") 或 @XXXMapping(path = "/path")
            Pattern valuePattern = Pattern.compile("@\\w+Mapping\\(\\s*(value|path)\\s*=\\s*\"([^\"]+)\"\\s*\\)");
            Matcher valueMatcher = valuePattern.matcher(annotation);
            if (valueMatcher.find()) {
                return valueMatcher.group(2);
            }
            
            // 匹配数组格式：@XXXMapping(value = {"/path1", "/path2"})
            Pattern arrayPattern = Pattern.compile("@\\w+Mapping\\(\\s*(value|path)\\s*=\\s*\\{\\s*\"([^\"]+)\"\\s*[,}]");
            Matcher arrayMatcher = arrayPattern.matcher(annotation);
            if (arrayMatcher.find()) {
                return arrayMatcher.group(2);
            }
            
            // 匹配复杂格式中的路径：@XXXMapping(value = "/path", method = RequestMethod.GET)
            Pattern complexPattern = Pattern.compile("@\\w+Mapping\\([^)]*?(?:value|path)\\s*=\\s*\"([^\"]+)\"");
            Matcher complexMatcher = complexPattern.matcher(annotation);
            if (complexMatcher.find()) {
                return complexMatcher.group(1);
            }
        } catch (Exception e) {
            log.debug("解析注解URL失败: {}", annotation, e);
        }
        
        return null;
    }
    
    /**
     * 检查方法是否有String[]参数
     */
    private boolean hasStringArrayParameter(MethodDataObject methodInfo) {
        return methodInfo.getParameters().stream()
                .anyMatch(param -> "String[]".equals(param.getParameterType()));
    }
    
    /**
     * 从注解中提取Redis队列的key
     */
    private String extractQueueKeyFromAnnotation(String annotation) {
        try {
            // 匹配简单格式：@XXX("queue:key")
            Pattern simplePattern = Pattern.compile("@\\w+\\(\\s*\"([^\"]+)\"\\s*\\)");
            Matcher simpleMatcher = simplePattern.matcher(annotation);
            if (simpleMatcher.find()) {
                return simpleMatcher.group(1);
            }
            
            // 匹配带属性格式：@XXX(value = "queue:key") 或 @XXX(key = "queue:key")
            Pattern valuePattern = Pattern.compile("@\\w+\\(\\s*(value|key|name)\\s*=\\s*\"([^\"]+)\"\\s*\\)");
            Matcher valueMatcher = valuePattern.matcher(annotation);
            if (valueMatcher.find()) {
                return valueMatcher.group(2);
            }
        } catch (Exception e) {
            log.debug("解析Redis队列key失败: {}", annotation, e);
        }
        return "";
    }

    /**
     * 检查是否是多线程入口
     */
    private boolean isThreadEntry(ClassDataObject classInfo, MethodDataObject methodInfo) {
        // 检查是否实现了Runnable接口
        if (classInfo.getInterfaces().contains("java.lang.Runnable") && 
            methodInfo.getMethodName().equals("run")) {
            return true;
        }
        
        // 检查是否实现了Callable接口
        if (classInfo.getInterfaces().contains("java.util.concurrent.Callable") && 
            methodInfo.getMethodName().equals("call")) {
            return true;
        }
        
        // 检查@Async注解
        if (methodInfo.getAnnotations().stream().anyMatch(a -> a.contains("@Async"))) {
            return true;
        }
        
        // 检查方法名和返回类型特征
        if (methodInfo.getMethodName().toLowerCase().contains("async") || 
            methodInfo.getMethodName().toLowerCase().contains("thread")) {
            String returnType = methodInfo.getReturnType();
            if (returnType != null && (
                returnType.contains("Future") || 
                returnType.contains("CompletableFuture") ||
                returnType.contains("Thread"))) {
                return true;
            }
        }
        
        return false;
    }

    /**
     * 获取线程业务逻辑描述
     */
    private String getThreadBusinessLogic(ClassDataObject classInfo, MethodDataObject methodInfo) {
        if (classInfo.getInterfaces().contains("java.lang.Runnable") && 
            methodInfo.getMethodName().equals("run")) {
            return "实现Runnable接口的run方法";
        }
        
        if (classInfo.getInterfaces().contains("java.util.concurrent.Callable") && 
            methodInfo.getMethodName().equals("call")) {
            return "实现Callable接口的call方法";
        }
        
        if (methodInfo.getAnnotations().stream().anyMatch(a -> a.contains("@Async"))) {
            return "使用@Async注解的异步方法";
        }
        
        return "返回Future或Thread的异步方法";
    }

    /**
     * 检查是否是Redis队列处理入口
     */
    private boolean isRedisQueueEntry(MethodDataObject methodInfo) {
        // 检查方法名特征
        String methodName = methodInfo.getMethodName().toLowerCase();
        if (methodName.contains("pop") || methodName.contains("poll") || methodName.contains("consume")) {
            // 检查返回类型
            String returnType = methodInfo.getReturnType();
            if (returnType != null && (returnType.contains("RedisTemplate") || 
                                     returnType.contains("StringRedisTemplate") ||
                                     returnType.contains("RedisConnection"))) {
                return true;
            }
            
            // 检查参数类型
            boolean hasRedisParameter = methodInfo.getParameters().stream()
                    .anyMatch(param -> param.getParameterType().contains("RedisTemplate") ||
                                     param.getParameterType().contains("StringRedisTemplate") ||
                                     param.getParameterType().contains("RedisConnection"));
            
            if (hasRedisParameter) {
                return true;
            }
        }
        
        // 检查Redis相关注解
        if (methodInfo.getAnnotations().stream().anyMatch(a -> 
            a.contains("@RedisQueue") || 
            a.contains("@RedisListener") || 
            a.contains("@RedisConsumer"))) {
            return true;
        }
        
        // 检查方法注释中的Redis队列关键字
        String methodComment = methodInfo.getMethodComment();
        if (methodComment != null && 
            (methodComment.toLowerCase().contains("redis queue") || 
             methodComment.toLowerCase().contains("redis消息队列") ||
             methodComment.toLowerCase().contains("redis list"))) {
            return true;
        }
        
        return false;
    }
} 